#ifndef PAGE_HANDELER_H
#define PAGE_HANDELER_H

#include <stddef.h>

#include "capi/cef_app_capi.h"
#include "capi/cef_base_capi.h"
#include "capi/cef_client_capi.h"
#include "capi/cef_life_span_handler_capi.h"
#include "capi/views/cef_browser_view_capi.h"
#include "capi/views/cef_window_capi.h"


#include "base.h"
#include "ipc/ipc_main.h"
#include "logger.h"
#include "tools/list.h"
#include "tools/log_util.h"

typedef struct _page_handler {
    cef_life_span_handler_t cef_life_span_handler;
    cef_client_t cef_client;
    cef_drag_handler_t cef_drag_handler;
    int browser_size;
} page_handler;

// cef_client_t--------------------------------------
// struct _cef_context_menu_handler_t* CEF_CALLBACK get_context_menu_handler(
//         struct _cef_client_t* self) {
//     // DEBUG_CALLBACK("get_context_menu_handler\n");
//     return NULL;
// }

// struct _cef_dialog_handler_t* CEF_CALLBACK get_dialog_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_dialog_handler\n");
//     return NULL;
// }

// struct _cef_display_handler_t* CEF_CALLBACK get_display_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_display_handler\n");
//     return NULL;
// }

// struct _cef_download_handler_t* CEF_CALLBACK get_download_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_download_handler\n");
//     return NULL;
// }

struct _cef_drag_handler_t* CEF_CALLBACK get_drag_handler(
        struct _cef_client_t* self);

// struct _cef_focus_handler_t* CEF_CALLBACK get_focus_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_focus_handler\n");
//     return NULL;
// }

// struct _cef_geolocation_handler_t* CEF_CALLBACK get_geolocation_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_geolocation_handler\n");
//     return NULL;
// }

// struct _cef_jsdialog_handler_t* CEF_CALLBACK get_jsdialog_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_jsdialog_handler\n");
//     return NULL;
// }

// struct _cef_keyboard_handler_t* CEF_CALLBACK get_keyboard_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_keyboard_handler\n");
//     return NULL;
// }

struct _cef_life_span_handler_t *CEF_CALLBACK get_life_span_handler(struct _cef_client_t *self);

// struct _cef_load_handler_t* CEF_CALLBACK get_load_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_load_handler\n");
//     return NULL;
// }

// struct _cef_render_handler_t* CEF_CALLBACK get_render_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_render_handler\n");
//     return NULL;
// }

// struct _cef_request_handler_t* CEF_CALLBACK get_request_handler(
//         struct _cef_client_t* self) {
//     DEBUG_CALLBACK("get_request_handler\n");
//     return NULL;
// }
// 处理渲染进程发送的消息
int CEF_CALLBACK on_process_message_received(struct _cef_client_t *self, struct _cef_browser_t *browser,
                                             struct _cef_frame_t *frame, cef_process_id_t source_process,
                                             struct _cef_process_message_t *message);

// cef_life_span_handler_t----------------------------------
void CEF_CALLBACK on_after_created(struct _cef_life_span_handler_t *self, struct _cef_browser_t *browser);

void CEF_CALLBACK on_before_close(struct _cef_life_span_handler_t *self, struct _cef_browser_t *browser);

// 拖动区域
/// Called whenever draggable regions for the browser window change. These can
/// be specified using the '-webkit-app-region: drag/no-drag' CSS-property. If
/// draggable regions are never defined in a document this function will also
/// never be called. If the last draggable region is removed from a document
/// this function will be called with an NULL vector.
///
void CEF_CALLBACK on_draggable_regions_changed(struct _cef_drag_handler_t *self, struct _cef_browser_t *browser,
                                                 struct _cef_frame_t *frame, size_t regionsCount,
                                                 cef_draggable_region_t const *regions);

// 初始化 window_delegate_t
page_handler *create_page_handler_t();

#endif